package main

import (
	"context"
	"encoding/json"
	"fmt"
	"github.com/apache/pulsar-client-go/pulsar"
	"go_19/core"
	"go_19/initialize"
	"time"
)

func main() {
	core.EmptyCli()
	option := initialize.ClientOption{
		URL:                     "pulsar://111.111.0.60:6650",
		ConnectionTimeout:       time.Second * time.Duration(3),
		OperationTimeout:        time.Second * time.Duration(30),
		MaxConnectionsPerBroker: 1,
	}
	client := initialize.PulsarClient(option)
	producer, err := client.CreateProducer(pulsar.ProducerOptions{
		Topic:           "to_topic",
		Name:            "ctz_test",
		DisableBatching: false,
	})
	if err != nil {
		fmt.Errorf("Pulsar test err", err)
		panic("Pulsar test err")
	}
	msg := make(map[string]interface{})
	for i := 0; i < 5; i++ {
		msg["num"] = i
		msg["date"] = time.Now().Format("2006-01-02 15:04:05")
		msgJson, _ := json.Marshal(msg)
		producer.Send(context.Background(), &pulsar.ProducerMessage{
			Payload: msgJson,
			//DeliverAfter: time.Duration(0),
		})
	}
	defer producer.Close()

}
